package ioc

import (
	"github.com/IBM/sarama"
)

func InitKafka() sarama.Client {
	cfg := sarama.NewConfig()
	cfg.Producer.Return.Successes = true
	cfg.Producer.Return.Errors = true
	cfg.Producer.Partitioner = sarama.NewConsistentCRCHashPartitioner

	client, err := sarama.NewClient([]string{"192.168.71.130:9092"}, cfg)
	if err != nil {
		panic(err)
	}
	return client
}
func InitAsyncProducer(client sarama.Client) sarama.AsyncProducer {
	res, err := sarama.NewAsyncProducerFromClient(client)
	if err != nil {
		panic(err)
	}
	return res
}
